package com.example.mybatis.mapper;

import com.example.mybatis.model.UserInfo;
import lombok.Data;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface UserInfoMapper {

//    @Select("select * from user_info")
    //    @Select("select * from user_info")
//    @Select("select id, username,`password`, age, gender,  phone, " +
//            "delete_flag as deleteFlag, create_time as createTime, update_time as updateTime" +
//            " from user_info")

//    @Results(id = "BaseMap", value = {
//            @Result(column = "delete_flag", property = "deleteFlag"),
//            @Result(column = "create_time", property = "createTime"),
//            @Result(column = "update_time", property = "updateTime")
//    })
    @Select("select * from user_info")
    List<UserInfo> selectAll();

    @Select("select * from user_info where id = #{id}")
    UserInfo selectAllById1(Integer id);

    @Select("select * from user_info where id = #{id}")
    List<UserInfo> selectAllById2(Integer id);

    @Select("select * from user_info where username = #{username} and password = #{password}")
    List<UserInfo> selectByNameAndPassword(String username, String password);

    @Options(useGeneratedKeys = true, keyProperty = "id")
    @Insert("insert into user_info(username, password, age) values (#{username}, #{password}, #{age})")
    Integer insertUser(UserInfo userInfo);

    @Delete("delete from user_info where id = #{id}")
    Integer deleteUser(Integer id);

    @Update("update user_info set delete_flag =#{deleteFlag} , phone = #{phone} where id = #{id}")
    Integer updateUser(UserInfo userInfo);
}
